package com.easy.controller;

import com.easy.bean.Category;
import com.easy.bean.Product;
import com.easy.service.ICategoryService;
import com.easy.service.IProductService;
import com.easy.util.LayData;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("product")
public class ProductController {
    @Autowired
    IProductService productService;

    @RequestMapping("list")
    @ResponseBody
    public LayData getProductList(Page page, String text){
        List<Product> list=productService.selectProduct(page,text);
        int count=productService.ProductCount(text);
        return new LayData(count,list);
    }

    @RequestMapping("delete")
    @ResponseBody
    public int deleteProduct(int proid){
        return productService.deleteProduct(proid);
    }

    @RequestMapping("add")
    @ResponseBody
    public int addProduct(Product product){
        return productService.addProduct(product);
    }

    @RequestMapping("edit")
    @ResponseBody
    public int editProduct(Product product){
        return productService.editProduct(product);
    }

}
